char* Base2UTF8(const char* base64, size_t len)
{
    assert(base64 != NULL);
    char *utf;
    printf("string base64: %s\n", base64);
    printf("len: %d\n", len);
    utf = malloc(len);
    int utfLen = EVP_DecodeBlock((u_char*)utf, (const u_char*)base64, len);
    printf("utflen: %d\n", utfLen);
    utf[utfLen]=0;
    if (utfLen <= 0 ) {
        free(utf);
        return NULL;
    }
    return utf;
}


char* GBK2UTF8(char* gbk, size_t len)
{
    assert(gbk != NULL);
    iconv_t cd;
    if ((cd  = iconv_open("UTF-8", "GB18030")) < 0) {
        printf("Get iconv handle failed!\n");
        return NULL;
    }
    size_t gbkLen;
    if (len == 0) {
        gbkLen = strlen(gbk);
    } else {
        gbkLen = len;
    }
    char** gbkPtr = &gbk;
    size_t utf8Len = gbkLen * 2;
    char* utf8 = malloc(utf8Len);
    memset(utf8, 0, utf8Len);
    char* utf8Ptr  = utf8;
    size_t res = iconv(cd, gbkPtr, &gbkLen, &utf8Ptr, &utf8Len);
    if (res < 0) {
        printf("Convert failed!\n");
        free(utf8);
        utf8 = NULL;
    }
    iconv_close(cd);

    return utf8;
}

char *clear_kh(char *str, int lens)
{
        int len = lens;
        int flag = 0;
        char *p1 = NULL;
        char *p2 = NULL;
        char tmp[50] = {0};
        char *tmpp = (char *) malloc(len);
        memset (tmpp, 0 , sizeof(tmpp));
        p1 = str;
        while (1)
        {
                p1 = strstr(p1, "<");
                if(p1 == NULL)
                        break;
                p1 += 1;
                p2 = strstr(p1, ">");
                if (p2 == NULL)
                        break;
                if (flag)
                {    
                        strcat(tmpp, ", ");
                        flag =0;
                }
                len = p2 - p1;
                memcpy(tmp, p1, len);
                strcat(tmpp, tmp);
                memset(tmp, 0 , sizeof(tmp));
                flag ++;
         }
        return tmpp;
        free(tmpp);
}



char getChar(char * s)
{

        int a=0;
        if(*s>='0'&&*s<='9') a=*s-'0';
        else if(*s>='a' && *s<='f') a=*s-'a'+10;
        else if(*s>='A' && *s<='F') a=*s-'A'+10;
        else return 0;
        a*=16;
        s++;
        if(*s>='0'&&*s<='9') a+=*s-'0';
        else if(*s>='a' && *s<='f') a+=*s-'a'+10;
        else if(*s>='A' && *s<='F') a+=*s-'A'+10;
        else return 0;
        return (char) a;

}

